#!/usr/bin/env python
'''
Created on 26.03.2014

@author: Jan-Patrick
'''
import pygame


class Screen():

   
    def __init__(self):
        import objects
        
        pygame.init()
        self.clock = pygame.time.Clock()
        self.surface = pygame.Surface((100, 100), pygame.SRCALPHA)
        self.image = pygame.image.load('ball.png')
        self.shot_objx = objects.bullet1.posX
        self.shot_objy = objects.bullet1.posY
        self.shot_obj  = objects.bullet1.bullet_obj
        self.xsize = 1024
        self.ysize = 786
        self.x = self.xsize/2
        self.y = self.ysize-65
        self.done = False
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode((self.xsize, self.ysize))

    def shotEvent(self):
        import objects
        
        objects.bullet1.bullet_obj = self.screen.blit(pygame.image.load('bullet2.png'), (objects.bullet1.posX, objects.bullet1.posY))
            
        



    def refreshScreen(self):
        import objects
            
        while not self.done:
            
                # will block execution until 1/60 seconds have passed
                # since the previous time clock.tick was called.
                self.clock.tick(60)
                '''---Refactoring: Moved to controller---
                for event in pygame.event.get():
                        if event.type == pygame.QUIT:
                                done = True'''
        
                #Spiel
                self.screen.fill((0, 0, 0))
                #pygame.draw.rect(screen, (255,0,0), pygame.Rect(x,y,20,20))
                self.screen.blit(pygame.image.load('ball.png'), (self.x, self.y))
                '''---Refactoring: Moved to controller---
                pressed = pygame.key.get_pressed()
                #if pressed[pygame.K_UP]: y -= 3
                #if pressed[pygame.K_DOWN]: y += 3
                if pressed[pygame.K_LEFT] and (x > 0):
                    objects.player1.move(-10)
                if pressed[pygame.K_RIGHT] and (x < xsize-50):
                    objects.player1.move(10)
        
                if pressed[pygame.K_UP] and (objects.bullet1.bullet_obj == None):
                    objects.bullet1.posX = objects.player1.posX+25
                    objects.bullet1.posY = objects.player1.posY +25
                    objects.bullet1.bullet_obj = screen.blit(pygame.image.load('bullet2.png'), (objects.bullet1.posX, objects.bullet1.posY))
        '''
        
        
                if objects.bullet1.bullet_obj != None:
                    objects.bullet1.posY -= 20
                    img = pygame.image.load('bullet2.png')
                    img = pygame.transform.scale(img, (10,42) )
                    objects.bullet1.bullet_obj = self.screen.blit(img, (objects.bullet1.posX, objects.bullet1.posY))
        
                    if objects.bullet1.posX > self.xsize or objects.bullet1.posY > self.ysize:
                        objects.bullet1.bullet_obj = None
                    if objects.bullet1.posX < 0 or objects.bullet1.posY < 0:
                        objects.bullet1.bullet_obj = None
        
        
                pygame.display.update() #Screen refresh

        